﻿using System;
using System.Collections.Generic;
using System.Text;
using KeePassLib;
using KeePass.UI;
using System.Windows.Forms;
using System.Linq;
using KeePassLib.Events;

namespace KeePass.Forms
{
    public class UserControlEditReadRights : UserControlEditRights
    {
        protected override bool CheckedStateToChangeToAfterUserListChanged
        { get { return true; } }

        public UserControlEditReadRights(AlternativeUser alternativeUser, PwDatabase db, CustomTreeViewEx ctmMainForm)
        {
            Construct(alternativeUser, db, ctmMainForm);
        }

        protected override void AddEventHandler(PwGroup group)
        {
            group.WritableUserAdded += new PwGroup.UserAddedRemovedHandler(ChangeCheckedStateUserListChanged);
        }
   
        protected override bool UsersContains(TreeNode t, AlternativeUser au)
        {
            return ((PwGroup)t.Tag).ReadableUsersContains(au);
        }

        protected override void AddUserToList(TreeNode t, AlternativeUser au)
        {            
            ((PwGroup)t.Tag).AddReadableUser(au);
        }

        protected override void RemoveUserFromList(TreeNode t, AlternativeUser au)
        {
            ((PwGroup)t.Tag).RemoveReadableUser(au);
        }

        protected override void CheckedStateChangedAction(PwGroup group)
        {
            group.AddReadableUser(altUser);
        }
    }
}
